home *** CD-ROM | disk | FTP | other *** search
- #include "callbackg.h"
- #include "sliders.h"
- #include "xfuns.h"
-
- extern ControlActionUPP scroller;
-
- static int busy = FALSE;
-
- static void ReEval(void) // force MathPad to re-evaluate its current document
- {
- GrafPtr wind;
-
- GetPort(&wind);
- DoMenuItem((131L<<16) | 13); // menuid=131 (MathPad) item=13 (Reevaluate)
- SetPort(wind);
- }
-
- pascal void ScrollProc(ControlHandle theControl,short part)
- {
- int bump;
-
- switch (part)
- {
- case inThumb: bump = 0; break;
- case inUpButton: bump = -1; break;
- case inDownButton: bump = 1; break;
- case inPageUp: bump =-10; break;
- case inPageDown: bump = 10; break;
- default: return;
- }
-
- if(!busy) // parser is not reentrant! Don't force ReEval if it hasn't finished last eval.
- {
- SetCtlValue(theControl,GetCtlValue(theControl)+bump);
- ReEval();
- }
- }
-
- static int DoControl(WindowPtr theWindow,Point where)
- {
- int part;
- ControlHandle theControl;
- GlobalToLocal(&where);
- part = FindControl(where,theWindow,&theControl);
- if(!part) return(FALSE); /* mousedown was not in a control */
-
- if(part == inThumb) /* Note: only kind of control is scrollbar */
- {
- TrackControl(theControl,where,0L);
- if(!busy) ReEval();
- }
- else
- TrackControl(theControl,where,scroller); /* 68K could just use &ScrollProc. PPC can't*/
- return(TRUE);
- }
-
- static int DoMouseDown(EventRecord *theEvent)
- {
- WindowPtr theWindow;
- int partCode;
- Rect sizeLimit;
- GrafPtr oldPort;
-
- partCode = FindWindow(theEvent->where,&theWindow);
-
- if(partCode == inMenuBar) return(FALSE);
- if(!IsSlider(theWindow)) return(FALSE);
-
- switch(partCode)
- {
- case inDrag:
- SetRect(&sizeLimit,0,25,4000,4000);
- SelectWindow(theWindow);
- DragWindow(theWindow,theEvent->where,&sizeLimit);
- break;
-
- case inContent:
- /*
- pseudo floating window trick. Don't select the window, but do
- the control anyway. This makes all slider controls active as if
- they were in front even if the window manager doesn't know it.
- */
- GetPort(&oldPort);
- SetPort(theWindow);
- DoControl(theWindow,theEvent->where);
- SetPort(oldPort);
- break;
-
- case inGoAway:
- if(TrackGoAway(theWindow,theEvent->where))
- {
- if(theEvent->modifiers & optionKey) KillAllSliders();
- else KillSlider(theWindow);
- }
- break;
- }
- return(TRUE);
- }
-
- static void Update(WindowPtr theWindow)
- {
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort(theWindow);
- BeginUpdate(theWindow);
- UpdtControl(theWindow,theWindow->visRgn);
- EndUpdate(theWindow);
- SetPort(oldPort);
- }
-
- short doevent(EventRecord *theEvent)
- {
- switch (theEvent->what)
- {
- case mouseDown:
- return DoMouseDown(theEvent);
-
- case updateEvt:
- if(IsSlider((WindowPtr)(theEvent->message)))
- {
- Update((WindowPtr)(theEvent->message));
- return(TRUE);
- }
- break;
-
- case activateEvt: // required event but no action needed
- return(IsSlider((WindowPtr)(theEvent->message)));
-
- case app3Evt: // message from MathPad
- if(theEvent->message == BEGINPARSE) busy = TRUE;
- else if(theEvent->message == ENDPARSE) busy = FALSE;
- break;
-
- case app4Evt:
- if((theEvent->message & 0xFF000000) == 0x01000000)
- {
- if(theEvent->message & 1) /* resume */
- activate();
- else /* suspend */
- deactivate();
- return(FALSE); // MathPad needs to do further processing on this event
- }
- else
- if((theEvent->message & 0xFF000000) == 0xFA000000) // mouse moved
- {
- if(IsSlider(FrontWindow())) // front window is required to handle mouse moved
- {
- SetCursorRegion(NULL,NULL); // just use arrow cursor
- return(TRUE);
- }
- }
- break;
- }
- return(FALSE);
- }
-
-